{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://docs.bokeh.org/en/latest/docs/gallery/texas.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'dict' object has no attribute 'head'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-cb936b047b77>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     11\u001b[0m \u001b[1;31m# counties\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0munemployment\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: 'dict' object has no attribute 'head'"
     ]
    }
   ],
   "source": [
    "from bokeh.io import show\n",
    "from bokeh.models import LogColorMapper\n",
    "from bokeh.palettes import Viridis6 as palette\n",
    "from bokeh.plotting import figure\n",
    "\n",
    "# Using data directory: C:\\Users\\zzz\\.bokeh\\data\n",
    "from bokeh.sampledata.us_counties import data as counties\n",
    "from bokeh.sampledata.unemployment import data as unemployment\n",
    "\n",
    "\n",
    "# counties\n",
    "# unemployment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "palette.reverse()\n",
    "\n",
    "counties = {\n",
    "    code: county for code, county in counties.items() if county[\"state\"] == \"tx\"\n",
    "}\n",
    "\n",
    "county_xs = [county[\"lons\"] for county in counties.values()]\n",
    "county_ys = [county[\"lats\"] for county in counties.values()]\n",
    "\n",
    "county_names = [county['name'] for county in counties.values()]\n",
    "county_rates = [unemployment[county_id] for county_id in counties]\n",
    "color_mapper = LogColorMapper(palette=palette)\n",
    "\n",
    "data=dict(\n",
    "    x=county_xs,\n",
    "    y=county_ys,\n",
    "    name=county_names,\n",
    "    rate=county_rates,\n",
    ")\n",
    "\n",
    "TOOLS = \"pan,wheel_zoom,reset,hover,save\"\n",
    "\n",
    "p = figure(\n",
    "    title=\"title  Texas Unemployment, 2009\", tools=TOOLS,\n",
    "    x_axis_location=None, y_axis_location=None,\n",
    "    tooltips=[\n",
    "        (\"Name\", \"@name\"), (\"Unemployment rate)\", \"@rate%\"), (\"(Long, Lat)\", \"($x, $y)\")\n",
    "    ])\n",
    "p.grid.grid_line_color = None\n",
    "p.hover.point_policy = \"follow_mouse\"\n",
    "\n",
    "p.patches('x', 'y', source=data,\n",
    "          fill_color={'field': 'rate', 'transform': color_mapper},\n",
    "          fill_alpha=0.7, line_color=\"white\", line_width=0.5)\n",
    "\n",
    "show(p)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
